// pages/agentPayLaunch/agentPayLaunch.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    order_id:'',//订单ID
    type:'',//代付类型1：订单代付 2:续费代付
    orderInfo:{},//订单详情
    userInfo:{},//用户详情
    order_no:'',//订单编号
    order_actual_money:'',//订单金额
    create_time:'',//下单时间

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //type说明： 1订单代付 2续费代付
    this.setData({
      order_id:options.order_id,
      type:options.type,//1：订单代付 2:续费代付
    })
    if(this.data.type==1){
      this.getOrderInfo();//订单详情
    }else if(this.data.type==2){
      this.getRenewOrderInfo();
    }
    this.getUserInfo();
    
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },



  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    var user_id = wx.getStorageSync('user_id');
    return {
      title: '我发起了代付请求,赶快进入支付吧',
      path: '/pages/agentPay/agentPay?order_id=' + that.data.order_id + "&uid="+user_id+"&type="+that.data.type+"&role=4"
    }
  },
   // 查询续费订单详情
 getRenewOrderInfo: function () {
  var that = this;
  var order_id = that.data.order_id;  // 订单ID
  app.ajax({
    url: 'User/Renew/getRenewOrderDetail',
    data: { renew_order_id: order_id },
    success: function (res) {
      if (res.data.code == 1000) {
        that.setData({
          orderInfo: res.data.data,
          order_no:res.data.data.renew_order_no,
          order_actual_money:res.data.data.order_actual_money,
          create_time:res.data.data.create_time
        });
      } else {
        app.showToast(res.data.message);
      }
      console.log('订单详情',res);
    }
  })
},
  //查询订单详情
  getOrderInfo:function(){
    var that = this;
    var order_id = that.data.order_id;
    app.ajax({
      url: 'User/Order/getOrderDetail',
      method: "POST",
      data: { order_id: order_id },
      success: function (res) {
        //console.log(res)
        if (res.data.code == 1000) {
          that.setData({
            orderInfo: res.data.data,
            order_no:res.data.data.order_no,
            order_actual_money:res.data.data.order_actual_money,
            create_time:res.data.data.create_time
          });
        } else {
          app.showToast(res.data.message);
        }
      }
    })
  },
    //获取用户信息
    getUserInfo() {
      var that = this;
      app.ajax({
        url: "User/User/getUserInfo",
        data: {},
        success: function(res) {
          wx.stopPullDownRefresh()
          if (res.data.code == 1000) {
            that.setData({
              userInfo: res.data.data
            })
          } else {
            app.showToast(res.data.message, "none", 2000, function() {});
          }
        
        }
      })
    },
  
})